home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODF-Interest Archive / June 96 / Re How to embed a part into yo < prev    next >
Encoding:
Internet Message Format  |  1996-12-03  |  6.4 KB  |  [TEXT/ttxt]

  1. Subject:     Re: How to embed a part into yourself (long)
  2. Sent:        6/13/96 6:09 PM
  3. Received:    6/13/96 6:21 PM
  4. From:        Damon Cokenias, cokenias@mtn-palace.com
  5. Reply-To:    ODF Interest, ODF-Interest@CILabs.ORG
  6. To:          OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
  7.  
  8. >Can someone point me to sample code or a routine that shows how to create a
  9. >part at run-time and embed in another part. For example, in response to the
  10. >user choosing the text tool from a palette and dragging a rectangle, create
  11. >a text part and embed it at the location the user specified.
  12.  
  13. Mark, I meant to put together a little note about this just last week but
  14. forgot.  Sorry.
  15.  
  16. I've done this in one of our internal parts here at Apple.  There are a few
  17. steps, none too difficult.
  18.  
  19. First, create an ODShape to be used as the frame shape.  Remember that the
  20. top-left corner of a frame shape should be {0,0} regardless of where the
  21. part will appear in your content.  (More on location later).
  22.  
  23.  
  24.         FW_CAcquiredODShape     frameShape = FW_NewODShape (ev, bounds);
  25.  
  26. Second, you need to obtain a reference to your document's draft and ask the
  27. draft to create a new ODPart.  Given an FW_CPart, the following code will
  28. work:
  29.  
  30.         ODStorageUnit*          su = myPart -> GetStorageUnit (ev);
  31.         ODDraft*                draft = su -> GetDraft (ev);
  32.         FW_CAcquiredODPart      newPart = draft ->
  33.                                         CreatePart (ev, kTextKind, kODNoEditor);
  34.  
  35. Note that in the above code, kTextKind would be the full ISO string
  36. describing the kind of data to be embedded.  kODNoEditor signifies that
  37. OpenDoc should feel free to choose which editor to use for the embedded
  38. data.  Instead, this parameter could be an ISO string for a particular
  39. editor.
  40.  
  41. Third, you need to construct a proxy object to represent the embedded part
  42. within yor content model.  See ODFEmbed and ODFDraw for examples of proxy
  43. objects.  Depending on your content model you may need a very simple or
  44. very complicated proxy object.
  45.  
  46.         CMyProxy*               myProxy = new CMyProxy (ev, myPart,
  47.                                         myPart -> GetMainPresentation ());
  48.  
  49. Finally, embed the newly created part in your content:
  50.  
  51.         myPart -> GetMainPresentation () -> Embed (ev, newPart, NULL,
  52. kODFrameObject,
  53.                         myProxy, frameShape, FW_CPart::gViewAsFrameToken,
  54. NULL, 0,
  55.                         FALSE, FALSE);
  56.  
  57. These many parameters could use some explaining:
  58.  
  59. ev                      That obnoxious SOM thing that almost every function
  60. takes as a
  61.                         parameter
  62. newPart                 The ODPart created by our document's draft
  63. NULL                    The ODFrame to embed.  In our case, we want a frame
  64. created for
  65.                         us.
  66. kODFrameObject          Suggested frame type.
  67. myProxy                 The subclass of FW_MProxy that will represent the
  68. embedded
  69.                         content.
  70. frameShape              The frame shape, with its origin at {0,0}
  71. gViewAsFrameToken       A tokenized ISO string describing how to embed the
  72. part.  (As
  73.                         icon, thumbnail, frame, etc.)
  74. NULL                    Presentation type.  NULL for default.
  75. 0                       Frame group ID.
  76. FALSE                   Is overlaid
  77. FALSE                   Is subframe
  78.  
  79.  
  80.  
  81.  
  82. Once the above steps have been taken, the containing frame's
  83. CreateEmbeddedFacet method will be called.  This is where you decide where
  84. to position the embedded content and how much of it to display.
  85.  
  86. Often you will simply want a facet that is the same size and shape as the
  87. frame shape, just at a particular location in your frame.  The code below
  88. positions the embedded part at {40,100}.
  89.  
  90. ODFacet* CMyFrame::CreateEmbeddedFacet (Environment* ev, ODFacet*
  91. embeddingFacet,
  92.                 FW_MProxy* proxy, ODFrame* embeddedFrame,
  93.                 ODShape* proposedClipShape) {
  94.  
  95.         FW_CAcquiredODTransform                 externalTransform;
  96.  
  97.         externalTransform = ::FW_NewODTransform (ev, FW_CPoint
  98. (FW_IntToFixed (40),
  99.                 FW_IntToFixed (100)));
  100.  
  101.  
  102.         return embeddeingFacet -> CreateEmbeddedFacet (ev, embeddedFrame,
  103.                 proposedClipShape, externalTransform, NULL, NULL, NULL,
  104.                 kODFrameInFront);
  105. }
  106.  
  107. Once again, a quick breakdown of the parameters.  First, the values passed
  108. to CreateEmbeddedFacet:
  109.  
  110. ev              Your favorite and mine.
  111. embeddingFacet  The containing facet.
  112. proxy           Your subclass of FW_MProxy that was passed to
  113.                 FW_CEmbeddingPresentation::Embed in the code above.
  114. embeddedFrame   The frame of the embedded part that will draw in the facet
  115. you create.
  116. proposedClipShape       This shape describes the shape of the facet that
  117. the embedded
  118.                         part would prefer to use.  It is at {0,0}.
  119.  
  120.  
  121. The parameters to CreateEmbeddedFacet:
  122.  
  123. ev                      How much time gets spent passing this parameter anyway?
  124. embeddedFrame           The embedded frame
  125. proposedClipShape       The (in this case unaltered) shape to use.  If you
  126. want to use
  127.                         a shape other than the proposed shape, you should create
  128.                         another shape object, not mess with the
  129. proposedClipShape
  130.                         directly.
  131. externalTransform       Where in the parent facet (your part's facet) the
  132. embedded
  133.                         facet should appear.
  134. NULL                    The canvas.  NULL means use same canvas as
  135. containing part.
  136. NULL                    The biasCanvas.  NULL because we are not using any funky
  137.                         drawing coordinates.
  138. NULL                    A sibling facet.  If there is already a facet for this
  139.                         embedded frame, pass it here.
  140. kODFrameInFront         Where the facet should be in relation to its
  141. sibling.  This
  142.                         does not really apply in this situation because
  143. there is only
  144.                         one facet for this frame.
  145.  
  146.  
  147.  
  148. Whew!
  149.  
  150.  
  151.  
  152.  
  153. If you remove all of my comments and maybe fix a spelling error or two,
  154. you'll probably be able to compile the above directly in to your part.
  155.  
  156. I hope this was of help!
  157.  
  158. -Damon
  159. Quality ODF Guy
  160.  
  161.  
  162. +-----------------------------------------------------------------------+
  163. |   /\    Damon Cokenias                                                |
  164. |  /^^\   cokenias@mtn-palace.com                                       |
  165. | /____\  Visit the Mountain Palace at http://www.netgate.net/~cokenias |
  166. +-----------------------------------------------------------------------+
  167.  
  168.